package edu.zut.software.identity.Service.impl;

import edu.zut.software.identity.Repository.StuMajorRepository;
import edu.zut.software.identity.Service.StuMajorService;
import edu.zut.software.identity.domain.StuMajor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StuMajorServiceImpl implements StuMajorService {
    private StuMajorRepository stuMajorRepository;
    @Autowired
    public void setStuMajorRepository(StuMajorRepository stuMajorRepository) {
        this.stuMajorRepository = stuMajorRepository;
    }

    @Override
    public void deleteById(String id) {
        stuMajorRepository.deleteById(id);
    }

    @Override
    public void save(StuMajor stuMajor) {
        stuMajorRepository.save(stuMajor);
    }

    @Override
    public StuMajor findById(String id) {
        return stuMajorRepository.findById(id).orElseThrow(RuntimeException::new);
    }

    @Override
    public List<StuMajor> findAll() {
        return stuMajorRepository.findAll();
    }

    @Override
    public List<StuMajor> getMajorInfoByCollegeId(String Id) {
        return stuMajorRepository.getMajorInfoByCollegeId(Id);
    }

    @Override
    public Page<StuMajor> findAll(Integer page, Integer pageSize) {
        Pageable pageable = PageRequest.of(page, pageSize);
        Page<StuMajor> pageInfo = stuMajorRepository.findAll(pageable);
        return pageInfo;
    }
}
